package com.yiwei.zxp.activity;

import android.os.Bundle;
import android.text.Spanned;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.api.Api;
import com.yiwei.zxp.api.bean.CommissionDetailBean;
import com.yiwei.zxp.api.model.CommissionDetailModel;
import com.yiwei.zxp.base.BaseActivity;
import com.yiwei.zxp.util.DateTime;
import com.yiwei.zxp.util.Network;
import com.yiwei.zxp.util.RxLifeUtil;
import com.yiwei.zxp.util.Spans;
import com.yiwei.zxp.util.ToastUtil;
import com.yiwei.zxp.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 17-12-8.
 */

public class CommissionWithdrawDetailActivity extends BaseActivity {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.txt_left_content)
    TextView txtLeftContent;
    @BindView(R.id.txt_right_content)
    TextView txtRightContent;
    private Unbinder unbiner;
    private int textSize26;
    private String status;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_commission_withdraw_detail);
        initBar();
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
//        txtTitle.setText("佣金提现详情");
//        txtTitle.setText("佣金到账详情");
        textSize26 = getResources().getDimensionPixelSize(R.dimen.x26);
        String id = getIntent().getStringExtra("id");
        status = getIntent().getStringExtra("status");
        if (status.equals("1")) {
            txtTitle.setText("佣金到账详情");
        } else if (status.equals("2")) {
            txtTitle.setText("佣金提现详情");
        }
        getDetail(id);
    }

    public void getDetail(String id) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        loadingDialog.show();

        CommissionDetailBean bean = new CommissionDetailBean();
        bean.id = id;
        Api.api_service.getCommissionDetail(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    setWithdrawData(result.datas);
                });
    }


    private void setWithdrawData(CommissionDetailModel.DatasBean item) {

        if (status.equals("1")) {
            Spanned txtLeft = Spans.with(this).font("被推荐人账号", textSize26, 0xff999999).
                    font("\n所购买展位套餐总额", textSize26, 0xff999999).
                    font("\n获得佣金", textSize26, 0xff999999).
                    font("\n到账时间", textSize26, 0xff999999).
                    font("\n推荐人姓名", textSize26, 0xff999999).
                    font("\n推荐人手机号码", textSize26, 0xff999999).
                    build();
            txtLeftContent.setText(txtLeft);
            Spanned txtRight = Spans.with(this).font(item.firend_account, textSize26, 0xff333333).
                    font("\n" + item.pay_money + "元", textSize26, 0xff333333).
                    font("\n" + item.commission + "元", textSize26, 0xff333333).
                    font("\n" + DateTime.toDateTime(item.time * 1000), textSize26, 0xff333333).
                    font("\n" + item.invite_name, textSize26, 0xff333333).
                    font("\n" + item.invite_phone, textSize26, 0xff333333).
                    build();
            txtRightContent.setText(txtRight);
        } else if (status.equals("2")) {
            Spanned txtLeft = Spans.with(this).font("提现账户", textSize26, 0xff999999).
                    font("\n到账银行", textSize26, 0xff999999).
                    font("\n提现金额", textSize26, 0xff999999).
                    font("\n提现手续费", textSize26, 0xff999999).
                    font("\n实际到账金额", textSize26, 0xff999999).
                    font("\n到账时间", textSize26, 0xff999999).
                    build();
            txtLeftContent.setText(txtLeft);
            Spanned txtRight = Spans.with(this).font(item.account, textSize26, 0xff333333).
                    font("\n" + item.bank, textSize26, 0xff333333).
                    font("\n" + item.money + "元", textSize26, 0xff333333).
                    font("\n" + item.rate + "%", textSize26, 0xff333333).
                    font("\n" + item.true_money + "元", textSize26, 0xff333333).
                    font("\n" + DateTime.toDateTime(item.apply_time * 1000), textSize26, 0xff333333).
                    build();
            txtRightContent.setText(txtRight);
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
        unbiner = null;
    }


    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
